﻿// Jeremy Lee
// Battle Tactics- A turn based strategy game
// Tile.cs- A class to represent the tiles
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace BattleTactics
{
    public class Tile
    {
        Texture2D sprite;
        string spritePath;
        public VectorInt loc;
        public Unit unit;
        public int type;
        public int moveCost;
        public TileState state;
        public Color tint;
        public int stupid;

        public Tile()
        {
            sprite = null;
            spritePath = "";
            loc = new VectorInt();
            unit = null;
            type = -1;
            moveCost = -1;
            tint = Color.White;
        }
        public Tile(int style)
        {
            switch (style)
            {
                case -2:
                    spritePath = "wall";
                    break;
                case 1:
                    spritePath = "tree";
                    break;
                case 2:
                    spritePath = "hill";
                    break;
                default:
                    spritePath = "grass";
                    break;
            }
            sprite = Globl.content.Load<Texture2D>("sprites\\" + spritePath);
            loc = new VectorInt();
            unit = null;
            type = style;
            moveCost = style + 1;
            tint = Color.White;
        }

        public void update()
        {
            if( state == TileState.NONE) 
                tint = Color.White;
            if (state == TileState.MOVE)
                tint = Color.LightBlue;
            if (state == TileState.ATTACK)
                tint = Color.Red;
        }

        public void draw(SpriteBatch sb)
        {
            sb.Draw(sprite, 
                    new Rectangle(loc.X * Globl.TILE_SIZE, 
                                  loc.Y * Globl.TILE_SIZE, 
                                  Globl.TILE_SIZE, 
                                  Globl.TILE_SIZE), 
                    new Rectangle( 0, 0, sprite.Width, sprite.Height),
                    tint, 0.0f, Vector2.Zero, SpriteEffects.None,
                    0.1f );
            if (unit != null && unit.alive)
            {
                unit.loc = loc;
                unit.draw(sb, loc);
            }
        }
    }
}
